﻿@model Zor_Web.Models.Base.V_Lease
@using Webdiyer.WebControls.Mvc;
@using Zor_Tools;
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>租赁管理</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/Styles/zor.css" rel="stylesheet" />
    <!-- 框架必要 -->
    <script src="~/Content/Scripts/jquery/jquery-1.9.1.min.js"></script>
    <script src="~/Content/Scripts/learunui-framework.js"></script>
    <script src="~/Content/Scripts/Zor_AJax.js"></script>
    <!-- 消息提示 -->
    <script src="~/Content/layer/layer.js"></script>
    <!-- 日期选择器 -->
    <script src="~/Content/laydate/laydate.js"></script>
    <!-- 税收算法 -->
    <script src="~/Content/Scripts/RatMoney.js"></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script>
    <!-- 框架必要 -->
    <script src="~/Content/LayerUI/src/layui.js"></script>
</head>
<body class="gray-bg">
    <div class="layui-tab layui-tab-brief main-tab-container ">
        <div class="col-sm-12 ct-padding">
            <div class="col-sm-9 ct-padding">
                <button id="btnAdd" class="layui-btn layui-btn layui-btn-small"><span class="glyphicon glyphicon-plus"></span> 新增</button>
                <button id="btnUpdate" class="layui-btn layui-btn-warm layui-btn-small"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>
                <button id="btnDelete" class="layui-btn layui-btn-danger layui-btn-small"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                <button id="btnApt" class="layui-btn layui-btn layui-btn-small"><span class="glyphicon glyphicon-jpy"></span> 产生受理单</button>
                <button id="btnMessage" class="layui-btn layui-btn-orchid layui-btn-small"><span class="glyphicon glyphicon-list-alt"></span> 详情</button>
                <button id="btnSearch" class="layui-btn layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <button id="btnExport" class="layui-btn layui-btn-springgreen  layui-btn-small"><span class="glyphicon glyphicon-share"></span> 导出</button>
                <button id="btnReplace" class="layui-btn layui-btn-blue layui-btn-small"><span class="glyphicon glyphicon-refresh"></span> 刷新</button>
            </div>
        </div>
    </div>
    <div class="col-sm-12  layui-tab-content">
        <div class="mail-box" style="overflow-x:scroll;white-space:nowrap;">
            <table class="layui-table" lay-skin="line">
                <thead>
                    <tr>
                        <th hidden></th>
                        <th></th>
                        <th>所在楼宇</th>
                        <th>房号</th>
                        <th>业主姓名</th>
                        <th>业主电话</th>
                        <th>房屋面积(㎡)</th>
                        <th>租户名称</th>
                        <th>租金(元/月)</th>
                        <th>租赁开始日期</th>
                        <th>租赁截止日期</th>
                        <th>租赁状态</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody id="accordion">
                    @foreach (var item in Model.PageData)
                    {
                        <tr>
                            <td hidden>@item.Lease_Id</td>
                            <td><input type="radio" name="chk" id="@item.Lease_Id" value="@item.Lease_Id" /></td>
                            <td>@item.Bd_Name</td>
                            <td>@item.Hs_Number</td>
                            <td>@item.NatPer_Name</td>
                            <td>@item.NatPer_Phone</td>
                            <td>@item.Hs_Proportion</td>
                            <td>@item.Tenant_Name</td>
                            <td>@(item.LeaseRent*0.01)</td>
                            <td>@TimeHelper.TimeStampToDateTime(item.Lease_StartTime.ToString(), TimeHelper.ToTimeType.link_ymd)</td>
                            <td>@TimeHelper.TimeStampToDateTime(item.Lease_EndTime.ToString(), TimeHelper.ToTimeType.link_ymd)</td>
                            <td>@item.statue</td>
                            <td>@item.Lease_Remarks</td>
                            <td hidden>@item.Lease_Type</td>
                            <td hidden>@item.Tenant_Id</td>
                            <td hidden>@item.HouseShopId</td>
                            <td hidden>@item.Hs_attribute</td>
                            <td hidden>@item.Hs_Id</td>  <!--17-->
                            <td hidden>@item.Uim_Id</td><!--18-->
                            <td hidden>@item.Uim_Name</td><!--19-->
                            <td hidden>@item.Bd_Id</td><!--20-->
                            <td hidden>@item.Bd_Flage</td><!--21-->
                        </tr>
                    }

                </tbody>

            </table>

            <div class="col-sm-12">
                <div class="col-sm-10">
                    @Html.Pager(Model.PageData, new PagerOptions { PageIndexParameterName = "index", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "bootstrappager", @class = "pagination" })
                </div>
                <div class="col-sm-2 to-righjt">
                    共 @Model.PageData.TotalItemCount 条记录，页 @Model.PageData.CurrentPageIndex/@Model.PageData.TotalPageCount
                </div>
            </div>
        </div>
    </div>




        <!-- 新增修改模态 -->
        <div id="myModalLease" hidden data-backdrop="static">
            <div id="divLease" class="layui-tab-content">
                <form class="form-horizontal m-t">
                    <div class="layui-form-item" hidden>
                        <label class="col-sm-3 layui-form-label">ID：</label>
                        <div class="col-sm-9">
                            <input id="Lease_Id" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="layui-form-item" hidden>
                        <label class="col-sm-3 layui-form-label">ID：</label>
                        <div class="col-sm-9">
                            <input id="HouseShopId" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">房屋或者商铺：</label>
                        <div class="col-sm-4">
                            <select id="Hs_Flag" class="form-control" onchange="SelectHousOrShop()">
                                <option value="0">--请选择--</option>
                                <option value="2">房屋</option>
                                <option value="1">商铺</option>
                            </select>
                        </div>
                        <label class="col-sm-2 layui-form-label" id="lblBdName">租赁楼宇：</label>
                        <div class="col-sm-4">
                            <select id="BdName" class="form-control"></select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label" id="lblUimName">租赁单元：</label>
                        <div class="col-sm-4">
                            <select id="UimName" class="form-control"></select>
                        </div>
                        <label class="col-sm-2 layui-form-label" id="lblNumber">租赁房号：</label>
                        <div class="col-sm-4">
                            <select id="Hs_Number" class="form-control"></select>
                        </div>
                    </div>
                    <div class="layui-form-item" hidden>
                        <label class="col-sm-2 layui-form-label" id="lblHs_HousUse">房屋用途：</label>
                        <div class="col-sm-4">
                            <select id="Hs_HousUse" class="form-control"></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">租户：</label>
                        <div class="col-sm-4">
                            <select name="temp" class="form-control" id="Tenant_Id"></select>
                        </div>
                        <label class="col-sm-2 layui-form-label">租金(元)：</label>
                        <div class="col-sm-4">
                            <input id="Lease_Rent" type="text" class="form-control" autofocus="autofocus" datacol="yes" err="租金">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">租赁开始日期：</label>
                        <div class="col-sm-4">
                            <input id="Lease_StartTime" class="laydate-icon form-control layer-date" autofocus="autofocus" datacol="yes" err="租赁起始时间" checkexpession="NotNull">
                        </div>
                        <label class="col-sm-2 layui-form-label">租赁结束日期：</label>
                        <div class="col-sm-4">
                            <input id="Lease_EndTime" class="laydate-icon form-control layer-date" autofocus="autofocus" datacol="yes" err="租赁结束日期" checkexpession="NotNull">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">备注：</label>
                        <div class="col-sm-10">
                            <input id="Lease_Remarks" type="text" class="form-control" autofocus="autofocus">
                        </div>
                    </div>
                </form>
                <div class="box-footer">
                    <button id="btnRentSure" class="btn btn-info pull-right">
                        <i class="fa fa-check"></i>提交
                    </button>
                </div>
            </div>
        </div>


        <!-- 受理单模态 -->
        <div id="myModalAT" hidden data-backdrop="static">
            <div id="divfromAcc" class="layui-tab-content">
                <form class="form-horizontal m-t">
                    <div class="layui-form-item" hidden>
                        <label class="col-sm-3 layui-form-label">ID：</label>
                        <div class="col-sm-8">
                            <input id="Lease_Id1" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">姓名：</label>
                        <div class="col-sm-4">
                            <input readonly id="Hs_ProprietorName" type="text" class="form-control" placeholder="请输入角色名称" autofocus="autofocus">
                        </div>
                        <label class="col-sm-2 layui-form-label">联系电话：</label>
                        <div class="col-sm-4">
                            <input readonly id="Hs_ProprietorPhone" type="text" class="form-control" placeholder="..." autofocus="autofocus">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">租赁开始日期：</label>
                        <div class="col-sm-4">
                            <input readonly id="Lease_StartTime1" name="Lease_StartTime1" type="text" class="form-control" autofocus="autofocus">
                        </div>
                        <label class="col-sm-2 layui-form-label">租赁截止日期：</label>
                        <div class="col-sm-4">
                            <input readonly id="Lease_EndTime1" name="Lease_EndTime1" type="text" class="form-control" autofocus="autofocus" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">税起日期：</label>
                        <div class="col-sm-4">
                            <input id="Acceptance_TaxStartTime" name="Acceptance_TaxStartTime" type="text" class="form-control laydate-icon layer-date" placeholder="请选择税收起始时间" autofocus="autofocus" />
                        </div>
                        <label class="col-sm-2 layui-form-label">税止日期：</label>
                        <div class="col-sm-4">
                            <input id="Acceptance_TaxEndTime" name="Acceptance_TaxEndTime" type="text" class="form-control laydate-icon layer-date" placeholder="请选择税收结束时间" autofocus="autofocus" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">产权属性：</label>
                        <div class="col-sm-4">
                            <select name="temp" class="form-control" id="Hs_Cqsx">
                                <option value="1">个人</option>
                                <option value="2">非个人</option>
                            </select>
                        </div>
                        <label class="col-sm-2 layui-form-label">房屋属性：</label>
                        <div class="col-sm-4">
                            <select name="temp" class="form-control" id="Hs_attribute" disabled="">
                                <option value="1">住宅</option>
                                <option value="2">非住宅</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">面积：</label>
                        <div class="col-sm-4">
                            <input readonly id="Hs_Proportion" type="text" class="form-control" placeholder="..." autofocus="autofocus">
                        </div>
                        <label class="col-sm-2 layui-form-label">租金(元)：</label>
                        <div class="col-sm-4">
                            <input readonly id="Lease_Rent1" type="text" class="form-control" placeholder="..." autofocus="autofocus">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">税号：</label>
                        <div class="col-sm-4">
                            <input id="Acceptance_TaxNumber" type="text" class="form-control" placeholder="..." autofocus="autofocus">
                        </div>
                        <label class="col-sm-2 layui-form-label">付款人/单位：</label>
                        <div class="col-sm-4">
                            <input readonly id="Tenant_Name" type="text" class="form-control" placeholder="..." autofocus="autofocus">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">地址：</label>
                        <div class="col-sm-9">
                            <input id="Acceptance_Address" type="text" class="form-control" placeholder="..." autofocus="autofocus">
                        </div>
                        <input id="Acceptance_PropertyTaxs" type="hidden" class="form-null"><!--房产税-->
                        <input id="Acceptance_PersonalTaxs" type="hidden" class="form-null"><!--个人所得税-->
                        <input id="Acceptance_Taxs" type="hidden" class="form-null"><!--税金-->
                        <input id="Acceptance_TotalTaxs" type="hidden" class="form-null"><!--计税总额-->
                    </div>

                </form>
            </div>
            <div class="box-footer">
                <button id="btnSureLease" class="btn btn-info pull-right">
                    <i class="fa fa-check"></i>提交
                </button>
            </div>
        </div>

        @using (Html.BeginForm("Zor_Lease", "Base", new RouteValueDictionary { { "Model", Model } }, FormMethod.Get))
        {
    <!-- 查询模态框 -->
            <div id="myModalSearch" hidden data-backdrop="static">
                <div id="divselectfrom" class="layui-tab-content">
                    <form class="form-horizontal m-t">
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">房号：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="Hs_Number" value="@Model.Hs_Number">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">业主姓名：</label>
                            <div class="col-sm-9">
                                <input id="NatPer_Name" type="text" class="form-control" name="NatPer_Name" value="@Model.NatPer_Name">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">房屋性质：</label>
                            <div class="col-sm-9">
                                <select name="Nature" class="form-control" id="Nature">
                                    <option value="@Model.Nature"></option>
                                    <option value="@Model.Nature">商用</option>
                                    <option value="@Model.Nature">民宅</option>
                                    <option value="@Model.Nature">商住两用</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">租户：</label>
                            <div class="col-sm-9">
                                <input id="Tenant_Name" type="text" class="form-control" name="Tenant_Name" value="@Model.Tenant_Name">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">租赁开始日期：</label>
                            <div class="col-sm-9">
                                <input id="Search_StartTime" class="laydate-icon form-control layer-date" name="Lease_StartTime" value="@Model.Lease_StartTime">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">租赁截止日期：</label>
                            <div class="col-sm-9">
                                <input id="Search_EndTime" class="laydate-icon form-control layer-date" name="Lease_EndTime" value="@Model.Lease_EndTime">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="col-sm-3 layui-form-label">租赁状态：</label>
                            <div class="col-sm-9">
                                <select name="statue" class="form-control" id="statue">
                                    <option value="@Model.statue">全部</option>
                                    <option value="@Model.statue">正常租赁</option>
                                    <option value="@Model.statue">已过期</option>
                                </select>
                            </div>
                        </div>
                    </form>
                    <div class="box-footer">
                        <button type="submit" class="btn btn-info pull-right">
                            <i class="fa fa-search"></i>查询
                        </button>
                    </div>
                </div>
            </div>
        }

        <!-- 详情模态 -->
        <div id="myModalMessage" hidden data-backdrop="static">
            <div id="divfrom" class="layui-tab-content">
                <form class="form-horizontal m-t">
                    <div class="layui-form-item">
                        <label class="col-sm-3 layui-form-label">房号：</label>
                        <div class="col-sm-3 layui-input" id="Hs_Number2"></div>
                        <label class="col-sm-3 layui-form-label">租户：</label>
                        <div class="col-sm-3 layui-input" id="Tenant_Name1"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-3 layui-form-label">租赁开始日期：</label>
                        <div class="col-sm-3 layui-input" id="Lease_StartTime2"></div>
                        <label class="col-sm-3 layui-form-label">租赁截止日期：</label>
                        <div class="col-sm-3 layui-input" id="Lease_EndTime2"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-3 layui-form-label">租金(元)：</label>
                        <div class="col-sm-3 layui-input" id="Lease_Rent2"></div>
                        <label class="col-sm-3 layui-form-label">备注：</label>
                        <div class="col-sm-3 layui-input" id="Lease_Remarks2"></div>
                    </div>
                </form>
            </div>
        </div>

        <!-- 导出模态 -->
        <form action="/Base/ExportLease" enctype="multipart/form-data" method="post" id="formDownload">
            <div id="exportHtml" style="display:none;">
                <div class="eh_wrap">
                    <div class="eh_head">
                        <p style="">请选择您要导出的数据列</p>
                    </div>
                    <table width="100%" cellpadding="5" cellspacing="0">
                        <tr>
                            <td><input id="Bd_Name" type="checkbox" value="楼宇名称" name="chk_list" checked="checked" /><label>楼宇名称</label></td>
                            <td><input id="Hs_Number" type="checkbox" value="房号" name="chk_list" checked="checked" /><label>房号</label></td>
                            <td><input id="NatPer_Name" type="checkbox" value="业主姓名" name="chk_list" checked="checked" /><label>业主姓名</label></td>
                            <td><input id="NatPer_Phone" type="checkbox" value="业主电话" name="chk_list" checked="checked" /><label>业主电话</label></td>
                        </tr>
                        <tr>
                            <td><input id="Hs_Proportion" type="checkbox" value="房屋面积" name="chk_list" checked="checked" /><label>房屋面积</label></td>
                            <td><input id="Tenant_Name" type="checkbox" value="租户名称" name="chk_list" checked="checked" /><label>租户名称</label></td>
                            <td><input id="Lease_Rent" type="checkbox" value="租金" name="chk_list" checked="checked" /><label>租金(元)</label></td>
                            <td><input id="Lease_StartTime" type="checkbox" value="租赁开始时间" name="chk_list" checked="checked" /><label>租赁开始时间</label></td>
                        </tr>
                        <tr>
                            <td><input id="Lease_EndTime" type="checkbox" value="租赁截止时间" name="chk_list" checked="checked" /><label>租赁截止时间</label></td>
                            <td><input id="statue" type="checkbox" value="租赁状态" name="chk_list" checked="checked" /><label>租赁状态</label></td>
                            <td><input id="Lease_Remarks" type="checkbox" value="备注" name="chk_list" checked="checked" /><label>备注</label></td>
                        </tr>
                    </table>
                    <div class="box-footer">
                        <button type="submit" id="btnExportSure" class="btn btn-info pull-right">
                            <i class="fa fa-repeat"></i>导出
                        </button>
                        <input type="hidden" id="LeaseMeg" name="LeaseMeg" value="" />
                        <input type="hidden" id="where" name="where" value="" />
                    </div>
                </div>
            </div>
        </form>
</body>
</html>

<script>   
  
    /*选择楼宇或者商铺*/
    function SelectHousOrShop()
    {
        $("#UimName").empty();
        $("#Hs_Number").empty();
        var Hs_Falg = $("#Hs_Flag").val();
        if (Hs_Falg == 1)
        {
            $("#lblBdName").html( "租赁街道:");
            $("#lblUimName").html("租赁门牌:");
            $("#lblNumber").html("租赁商铺编号:");
            SelectBuildingName(Hs_Falg);
        }
        if (Hs_Falg == 2)
        {
            $("#lblBdName").html("租赁楼宇:");
            $("#lblUimName").html("租赁单元:");
            $("#lblNumber").html("租赁房号:");
            SelectBuildingName(Hs_Falg);
        }
    }

     /**
      * 获取所属楼宇、街道
      */
    function SelectBuildingName(HsFalg) {
        var html = "";
        getAjax("/Base/GetBuildname", { "Hs_Falg": HsFalg }, function (data) {           
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Bd_Id + "' >" + accordionJson[i].Bd_Name + "</option>";
            });
        });
        $("#BdName").empty().append(html);
        
        /*选择楼宇下拉框事件 */
        $('#BdName').change(function () {
            var Bd_Id = $("#BdName").val();
            GetUimName(Bd_Id); //加载单元信息
        });
    }

    /**
     * 获取所属单元、门牌
     */
    function GetUimName(BdId) {
        $("#UimName").empty();
        var html = "";
        getAjax("/Base/GetLeaseUimName", { "Bd_Id": BdId }, function (data) {
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Uim_Id + "' >" + accordionJson[i].Uim_Name + "</option>";

            });
        });
        $("#UimName").empty().append(html);

        /*选择单元下的房屋信息 */
        $('#UimName').change(function () {
            var Uim_Id = $("#UimName").val();
            GetHousName(Uim_Id); //加载房屋信息         
        });
    }
   
    /**
     * 获取房号、门牌号
     */
    function GetHousName(UimId) {
        $("#Hs_Number").empty();       
        var html = "";
        getAjax("/Base/GetHousName", { "Uim_Id": UimId }, function (data) {
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Hs_Id + "' >" + accordionJson[i].Hs_Number + "</option>";
            });
        });
        $("#Hs_Number").empty().append(html);

        /*选择单元下的房屋用途 */
        $('#Hs_Number').change(function () {
            var Hs_Id = $("#Hs_Number").val();         
            GetHousUse(Hs_Id); //加载房屋用途        
        });
    }

    /**
    * 获取房屋用途
    */
    function GetHousUse(HsId) {
        $("#Hs_HousUse").empty();
        var html = "";
        getAjax("/Base/GetHousUse", { "Hs_Id": HsId }, function (data) {
            accordionJson = eval("(" + data + ")");         
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Hs_HousUse + "' >" + accordionJson[i].Hs_HousUse + "</option>";
            });
        });
        $("#Hs_HousUse").empty().append(html);
    }
    /**
    *   日期选择器
    */
    laydate.skin('molv');         //日历皮肤
    var start = {                   //开始时间选择
        elem: "#Lease_StartTime",
        format: "YYYY-MM-DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) {
            end.min = datas;
            end.start = datas;
            
        }
    };
    var end = {                     //结束时间选择
        elem: "#Lease_EndTime",
        format: "YYYY-MM-DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) { start.max = datas;datas }
    };
    var taxstart = {                   //开始时间选择
        elem: "#Acceptance_TaxStartTime",
        format: "YYYY-MM-DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) {
            end.min = datas;
            end.start = datas

        }
    };
    var taxend = {                     //结束时间选择
        elem: "#Acceptance_TaxEndTime",
        format: "YYYY-MM-DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) { start.max = datas }
    };
    laydate(start);
    laydate(end);
    laydate(taxstart);
    laydate(taxend);

    /**
    *   日期选择器---查询租赁日期
    */
    laydate.skin('molv');         //日历皮肤
    var startS = {                   //开始时间选择
        elem: "#Search_StartTime",
        format: "YYYY/MM/DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) {
            end.min = datas;
            end.start = datas
        }
    };
    var endS = {                     //结束时间选择
        elem: "#Search_EndTime",
        format: "YYYY/MM/DD",
        min: '1900-01-01',
        max: "2099-06-16",
        istime: false,
        istoday: true,
        choose: function (datas) { start.max = datas }
    };
    laydate(startS);
    laydate(endS);

    //查询
    $(function () {
        $("#btnSearch").click(function () {
            ClearWebControls(divfrom);
            LayerOpen('650px', '430px', '租赁查询', $('#myModalSearch'));
        })
    })

    /**
    * 新增租赁信息
    */
    $(function () {
        $("#btnAdd").click(function () {         
            ClearWebControls(divLease);
            GetTenant();
                 
            LayerOpen('800px', '360px', '租赁新增', $('#myModalLease'));
        })
    })
    /**
   * 修改租赁信息
   */
    $(function () {
        $("#btnUpdate").click(function () {
            var checkId = CheckboxValueIDs();
            if (checkId.length == 0) {
                layer.msg("请选择要修改的租赁信息！");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一行信息修改！");
                return;
            }
            var Bd_Flage = getTableCell(21);  //楼宇、街道标示
            var Bd_Id = getTableCell(20); //楼宇ID
            var Uim_Id = getTableCell(18); //单元ID
            var Hs_Id = getTableCell(17); //房屋ID
            var Bd_Name = getTableCell(3);    //获取选中行楼宇名称
            var Lease_StartTime = getTableCell(9);    //获取选中行的开始时间
            var Tenant_Id = getTableCell(14);    //获取选中行的租户Id
            var Lease_EndTime = getTableCell(10);    //获取选中行的结束时间
            var Lease_Rent = getTableCell(8);    //获取选中行的租金
            var Lease_Remarks = getTableCell(12);    //获取选中行的备注
            var Lease_Type = getTableCell(13);        //获取选中行的租赁类型

            SelectHousOrShop();  //加载选择房屋或商铺 
            SelectBuildingName(Bd_Flage); //加载楼宇信息
            GetUimName(Bd_Id); //加载单元信息 
            GetHousName(Uim_Id); //加载房屋信息 
            GetHousUse(Hs_Id);//加载房屋用途
            GetTenant();//加载租户信息

            $("#Hs_Flag").val(Bd_Flage);
            $("#BdName").val(Bd_Id);
            $("#UimName").val(Uim_Id);
            $("#Hs_Number").val(Hs_Id);
            $("#Lease_Id").val(getTableCell(0));         
            $("#Tenant_Id").val(Tenant_Id);
            $("#Lease_StartTime").val(Lease_StartTime);
            $("#Lease_EndTime").val(Lease_EndTime);
            $("#Lease_Rent").val(Lease_Rent);
            $("#Lease_Remarks").val(Lease_Remarks);
          
        
            LayerOpen('800px', '360px', '租赁修改', $('#myModalLease'));
        })
    })


    /**
    * 保存新增、修改租赁
    */
    $(function () {
        $("#btnRentSure").click(function () {

            if ($("#Hs_Flag").val() == 0)
            {
                layer.msg("请选择房屋或者商铺!", 0);
                return;
            }

            if ($("#BdName").val() == 0)
            {
                layer.msg("请选择楼宇或者街道!", 0);
                return;
            }
            if ($("#UimName").val() == 0) {
                layer.msg("请选择单元或者门牌!", 0);
                return;
            }
            if ($("#Hs_Number").val() == 0) {
                layer.msg("请选择要租赁房屋或者商铺!", 0);
                return;
            }
            var Hs_HousUse = $("#Hs_HousUse").val();          
            if (Hs_HousUse != 3)
            {
                 layer.msg("当前房屋为空置房屋或者自住房屋，不能产生租赁关系!", 0);
                 return;
            }
            if ($("#Lease_Rent").val() == 0) {
                layer.msg("请选择租户!", 0);
                return;
            }
            if ($("#Lease_StartTime").val() == 0) {
                layer.msg("请选择租赁开始日期!", 0);
                return;
            }
            if ($("#Lease_EndTime").val() == 0) {
                layer.msg("请选择租赁结束日期!", 0);
                return;
            }

            var LeaseRent = $("#Lease_Rent").val(); //增加，修改租赁管理时获取租金
            if (LeaseRent == "") {
                layer.msg("请输租金!", 0);
                return;
            }
            if (!LeaseRent.match(/^\d+(\.\d{2})?$/)) {
                layer.msg("租金输入有误,请输入到小数点后面两位！", 0);
                return;
            }
            if (LeaseRent == 0) {
                layer.msg("租金输入有误,租金不能为0元", 0);
                return;
            }

            $("#HouseShopId").val($("#Hs_Number").val());
           
            var JsData = GetWebControls(divLease);
            var Lease_StartTime = $("#Lease_StartTime").val();
            var Lease_EndTime = $("#Lease_EndTime").val();
            ZorPostSimpleData("/Base/AddLease", JSON.stringify({ "lease": JsData, "startTime": Lease_StartTime, "endTime": Lease_EndTime }), function (data) {
                layer.msg(data.AnswerMeg, function () {
                    layer.closeAll();
                    Replace();
                });
            });
        })
    })
    /**
    * 新增受理单信息
    */

    $(function () {
        $("#btnApt").click(function () {          
            var checkId = CheckboxValueIDs();           //获取选中行的租赁信息ID
            var Hs_ProprietorName = getTableCell(4);    //获取选中行的业主姓名
            var Hs_ProprietorPhone = getTableCell(5);   //获取选中行的业主电话
            var Hs_Proportion = getTableCell(6);        //获取选中行的房屋房屋面积
            var Lease_StartTime1 = getTableCell(9);      //获取选中行的租赁开始日期
            var Lease_EndTime1 = getTableCell(10);       //获取选中行的租赁截止日期
            var Lease_Rent1 = getTableCell(8);           //获取选中行的租金
            var Tenant_Name = getTableCell(7);          //获取选中行的租户名称
            var Hs_attribute = getTableCell(16);         //房屋属性           
            if (checkId.length == 0) {
                layer.msg("请选择要产生受理单的租赁信息！");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一条租赁信息产生受理单！");
                return;
            }
            
            $("#Lease_Id1").val(checkId[0]);
            $("#Hs_ProprietorName").val(Hs_ProprietorName);
            $("#Hs_ProprietorPhone").val(Hs_ProprietorPhone);
            $("#Hs_Proportion").val(Hs_Proportion);
            $("#Lease_Rent1").val(Lease_Rent1);
            $("#Lease_StartTime1").val(Lease_StartTime1);
            $("#Lease_EndTime1").val(Lease_EndTime1);           
            $("#Tenant_Name").val(Tenant_Name);
            $("#Hs_attribute").val(Hs_attribute);
            $("#Acceptance_TaxStartTime").val(Lease_StartTime1);
            $("#Acceptance_TaxEndTime").val(Lease_EndTime1);
            LayerOpen('800px', '450px', '受理单新增', $('#myModalAT'));
        })
    })

   

    /**
    * 保存受理单信息
    */
    $(function () {
        $("#btnSureLease").click(function () {
            var b=getTableCell(11);
            //计算房产税、个税

            if ($("#Acceptance_TaxStartTime").val() == "") {
                layer.msg("税收开始日期不能为空！");
                return;
            }
            if ($("#Acceptance_TaxEndTime").val() == "") {
                layer.msg("税收结束日期不能为空！");
                return;
            }

            if (!checkEndTime($("#Lease_StartTime1").val(), $("#Acceptance_TaxStartTime").val())) {
                layer.msg("税收起始时间必须晚于租赁起始时间！");
                return;
            }

            if (b =="已过期") {
                layer.msg("当前租赁关系已过期，不能产生受理单！");
                return;
            }
                       
            var bgDate = $("#Acceptance_TaxStartTime").val();
            var endDate = $("#Acceptance_TaxEndTime").val();
            var rentMoney = $("#Lease_Rent1").val();          
            var type = $("#Hs_attribute").val();
            getRatMoney(bgDate, endDate, rentMoney, type);

            var LeaseIds = $("#Lease_Id1").val();
            var PropertyTax = fcRat.toFixed(2) * 100;
            var PersonalTax =GrRat.toFixed(2) * 100;
            var Acceptance_Tax = jszje.toFixed(2)*100;

            var Acceptance_TotalTax = totalRent.toFixed(2) * 100;            
            var Acceptance_TaxNumber = $("#Acceptance_TaxNumber").val();
            var Acceptance_Address = $("#Acceptance_Address").val();         
            ZorPostSimpleData("/Base/InsertAcceptance", JSON.stringify({ 'LeaseId': LeaseIds, 'PropertyTax': PropertyTax, "PersonalTax": PersonalTax, "Acceptance_Tax": Acceptance_Tax, "Acceptance_TotalTax": Acceptance_TotalTax, "Acceptance_TaxNumber": Acceptance_TaxNumber, "Acceptance_Address": Acceptance_Address, "startTime": bgDate, "endTime": endDate }), function (data) {            
                layer.msg(data.AnswerMeg, function () {
                    layer.closeAll();
                    Replace();
                });
            });
        })
    })



    ///详情
    $(function () {
        $("#btnMessage").click(function () {
            //GetHsNumber();
            GetTenant();
            var checkId = CheckboxValueIDs();
            var Hs_Number2 = getTableCell(3);    //获取选中行的房屋Id
            var Lease_StartTime2 = getTableCell(9);    //获取选中行的开始时间
            var Tenant_Name1 = getTableCell(7);          //获取选中行的租户名称
            var Lease_EndTime2 = getTableCell(10);    //获取选中行的结束时间
            var Lease_Rent2 = getTableCell(8);    //获取选中行的租金
            var Lease_Remarks2 = getTableCell(12);    //获取选中行的备注
            var HouseShopId2 = getTableCell(15);
            $("#Lease_Id").attr("disabled", "disabled");
            if (checkId.length == 0) {
                layer.msg("请选择要查看的租赁信息！");
                $("#myModalMessage").attr("ID", "test");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一行信息查看！");
                $("#myModalMessage").attr("ID", "test");
                return;
            }            
            LayerOpen('600px', '230px', '租赁详情', $('#myModalMessage'));
            $("#Lease_Id").html(checkId[0]);
            $("#Hs_Number2").html(Hs_Number2);
            $("#Tenant_Name1").html(Tenant_Name1);
            $("#Lease_StartTime2").html(Lease_StartTime2);
            $("#Lease_EndTime2").html(Lease_EndTime2);
            $("#Lease_Rent2").html(Lease_Rent2);
            $("#Lease_Remarks2").html(Lease_Remarks2);
            $("#HouseShopId2").html(HouseShopId2);
        })
    })


    /**
    * 删除租赁信息
    */
    $(function () {
        $("#btnDelete").click(function () {
            var checkId = CheckboxValueIDs();
            if (checkId.length == 0) {
                layer.msg("请选择要删除的租赁信息！");                                                             //未选中任何行
                return;
            }
            else {
                layer.confirm("确定要删除吗?", { icon: 2, btn: ['确定', '取消'] }, function () {
                    ZorPostSimpleData("/Base/DeleteLease", JSON.stringify({ 'id': checkId }), function (data) { //获取数据(带参数)
                        if (data.AnswerType == 1)
                            Replace();
                        layer.msg(data.AnswerMeg);
                    })
                })
            }
        })
    })

    /**
    * 刷新
    **/
    $(function () {
        $("#btnReplace").click(function () {
            Replace();
        })
    })


    /**
    * 全选
    */
    $(function () {
        $("#cbkCheckAll").click(function () {
            if (this.checked) {
                $("input[name='chk']").prop('checked', true);
            } else {
                $("input[name='chk']").prop('checked', false);
            }
        })
    })

    /**
   * 查询所有租户
   */
    function GetTenant() {
        var html = "";
        getAjax("/Base/GetTenant", "", function (data) {
            accordionJson = eval("(" + data + ")");
            html += "<option value='0' >-请选择-</option>";
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Tenant_Id + "' >" + accordionJson[i].Tenant_Name + "</option>";
            });
        });
        $("#Tenant_Id").empty().append(html);
    }


    /*导出*/
    $("#btnExport").click(function () {
        layer.open({
            type: 1,
            title: '导出提示',
            shade: false,
            skin: 'layui-layer-rim',
            area: ['620px', '280px'], //宽高
            content: $('#exportHtml')
        });
    });
    /*导出交互*/
    $("#btnExportSure").click(function () {
        var arr = new Array();
        $("[name='chk_list']").each(function () {
            if ($(this).is(":checked")) {
                arr.push($(this).attr("id") + "|" + $(this).val());
            }
        });
        $("#LeaseMeg").val(arr);
        document.getElementById('formDownload').submit();
        layer.closeAll();
    });

    function checkEndTime(startTime, endTime) {
        var start = new Date(startTime.replace("-", "/").replace("-", "/"));
        var end = new Date(endTime.replace("-", "/").replace("-", "/"));
        if (end < start) {
            return false;
        }
        return true;
    }
</script>

